<?php echo \Fuel\Core\Asset::css("uploadfilemulti.css");?>
<?php echo \Fuel\Core\Asset::js("jquery.fileuploadmulti.min.js");?>
<script type="text/javascript">
    $(window).on('load', function () {

        $('.selectpicker').selectpicker({
            'selectedText': 'cat'
        });
            
        // $('.selectpicker').selectpicker('hide');
    });
</script>

<script>

$(document).ready(function()
{
    var i = 0;
    var settings = {
        url: "<?php echo \Fuel\Core\Uri::create('frontend/post/ajaxUploadFile');?>",
        method: "POST",
        allowedTypes:"jpg,png,doc,pdf,doc,docx",
        fileName: "myfile",
        multiple: true,
        onSuccess:function(files,data,xhr)
        {
            var obj = JSON.parse(data);
            console.log(obj.newName);
            console.log(obj.oldName);
            $(".upload-filename").each(function (){
                if($(this).text().search(obj.oldName) != -1)
                {
                    $(this).parent().attr("id", "file_"+i);
                }
            });
//            $(".upload-green:eq("+i+")").attr("id", i);
            var inputHtml = "<input type='hidden' value='"+ obj.newName +"' name='file["+i+"]' id='file_"+i+"'>";
            $('#files').prepend($(inputHtml));
            i++;
        },
        afterUploadAll:function()
        {

        },
        onError: function(files,status,errMsg)
        {	

        }
    }
    
    $("#mulitplefileuploader").uploadFile(settings);
    
    $(".upload-green").click(function(){
    alert("adfadsf");
        //alert($(this).parent().attr("id"));
    });
});
</script>

<div class="row">
    <div class="col-xs-9 box space-section">
        <div class="row">
            <div class="col-xs-12">
                <br>
                <p>Cùng chung tay xây dưng một thư viện các đề thi cuối kỳ, khóa luận, bài tập lớp, đồ án, để chúng ta có kiến thức tốt nhất trước khi đi thi. </p> 
                <p class="title"><strong>Đăng đề thi</strong></p>
            </div>
            <?php echo Fuel\Core\Form::open(array('class' => 'form-horizontal col-xs-12'));?>
            <div class="form-group">
                <?php echo Fuel\Core\Form::label('Tiêu đề <abbr>*<abbr>', 'title', array('class' =>'col-xs-2 control-label'));?>
                <div class="col-xs-10">
                    <?php echo Fuel\Core\Form::input(
                            'title', 
                            Fuel\Core\Input::post('title', isset($post) ? $post->title : ''), 
                            array('class' => 'form-control', 'placeholder' => '')
                    );?>
                    <span class="errorMessage"><?php echo isset($valid['title']) ? $valid['title'] : '';?></span>
                </div>
            </div>
            
            <div class="form-group">
                <?php echo Fuel\Core\Form::label('Mô tả <abbr>&nbsp</abbr>', 'description', array('class' => 'col-xs-2 control-label'));?>
                <div class="col-xs-10">
                    <?php echo Fuel\Core\Form::textarea('description', '', array('class' => 'form-control', 'rows' => 4));?>
                    <span class="errorMessage"><?php echo isset($valid['description']) ? $valid['description'] : '';?></span>
                </div>
            </div>
            <?php echo \Fuel\Core\Form::hidden("university_id",1);?>
            <!-- <div class="form-group">
                <?php echo Fuel\Core\Form::label('Trường <abbr>*<abbr>', 'university_id', array('class' =>'col-xs-2 control-label'));?>
                <div class="col-xs-4">
                    <?php echo Fuel\Core\Form::select(
                            'university_id', 
                            Fuel\Core\Input::post('university_id', isset($post) ? $post->university_id : ''), 
                            $university,
                            array('class' => 'form-control selectpicker show-tick', 'data-live-search' => true, 'id' => 'bs3Select' )
                    );?>
                </div>
                <div class="col-xs-1">OR</div>
                <div class="col-xs-5">
                    <?php echo Fuel\Core\Form::input(
                            'university', 
                            Fuel\Core\Input::post('university', isset($post) ? $post->university : ''), 
                            array('class' => 'form-control', 'placeholder' => '')
                    );?>
                </div>
                <div class="col-xs-offset-2 col-xs-10">
                    <span class="errorMessage"><?php echo isset($valid['university_id']) ? $valid['university_id'] : '';?></span>
                    <span class="errorMessage"><?php echo isset($valid['university']) ? $valid['university'] : '';?></span>
                </div>
            </div> -->
            
            <div class="form-group">
                <?php echo Fuel\Core\Form::label('Môn học <abbr>*<abbr>', 'course_id', array('class' =>'col-xs-2 control-label'));?>
                <div class="col-xs-10">
                    <?php echo Fuel\Core\Form::select(
                            'course_id', 
                            Fuel\Core\Input::post('course_id', isset($post) ? $post->course_id : ''), 
                            $course,
                            array('class' => 'form-control selectpicker show-tick', 'data-live-search' => true, 'id' => 'bs3Select' )
                    );?>
                </div>
                <!--<div class="col-xs-1">OR</div>
                <div class="col-xs-5">
                    <?php echo Fuel\Core\Form::input(
                            'course', 
                            Fuel\Core\Input::post('course', isset($post) ? $post->course : ''), 
                            array('class' => 'form-control', 'placeholder' => '')
                    );?>
                </div>-->
                <div class="col-xs-offset-2 col-xs-10" style="margin-top: 5px;">
                    <span class="errorMessage"><?php echo isset($valid['course_id']) ? $valid['course_id'] : '';?></span>
                    <span class="errorMessage"><?php echo isset($valid['course']) ? $valid['course'] : '';?></span>
                </div>
            </div>
            
            <div class="form-group">
                <?php echo Fuel\Core\Form::label('Giảng viên <abbr>*<abbr>', 'teacher_id', array('class' =>'col-xs-2 control-label'));?>
                <div class="col-xs-4">
                    <?php echo Fuel\Core\Form::select(
                            'teacher_id', 
                            Fuel\Core\Input::post('teacher_id', isset($post) ? $post->teacher_id : ''), 
                            $teacher,
                            array('class' => 'form-control selectpicker show-tick', 'data-live-search' => true, 'id' => 'bs3Select')
                    );?>
                </div>
                <div class="col-xs-1">OR</div>
                <div class="col-xs-5">
                    <?php echo Fuel\Core\Form::input(
                            'teacher', 
                            Fuel\Core\Input::post('teacher', isset($post) ? $post->teacher : ''), 
                            array('class' => 'form-control', 'placeholder' => '')
                    );?>
                </div>
                <div class="col-xs-offset-2 col-xs-10">
                    <span class="errorMessage"><?php echo isset($valid['teacher_id']) ? $valid['teacher_id'] : '';?></span>
                    <span class="errorMessage"><?php echo isset($valid['teacher']) ? $valid['teacher'] : '';?></span>
                </div>
            </div>
            
            <div class="form-group">
                <?php echo Fuel\Core\Form::label('Năm <abbr>*<abbr>', 'year', array('class' =>'col-xs-2 control-label'));?>
                <div class="col-xs-4">
                    <?php echo Fuel\Core\Form::select(
                            'year', 
                            Fuel\Core\Input::post('year', isset($post) ? $post->year : ''), 
                            $year,
                            array('class' => 'form-control selectpicker show-tick', 'data-live-search' => true, 'id' => 'bs3Select', 'prompt' => 'Chọn năm')
                    );?>
                    <span class="errorMessage"><?php echo isset($valid['year']) ? $valid['year'] : '';?></span>
                </div>
                <div class="col-xs-1">Kiểu</div>
                <div class="col-xs-5">
                    <?php echo Fuel\Core\Form::select(
                            'type_id', 
                            Fuel\Core\Input::post('type_id', isset($post) ? $post->type_id : ''), 
                            $type,
                            array('class' => 'form-control')
                    );?>
                    <span class="errorMessage"><?php echo isset($valid['type_id']) ? $valid['type_id'] : '';?></span>
                </div>
            </div>
            
            <div class="form-group">
                <?php echo Fuel\Core\Form::label('Tải file <abbr>*</abbr>', 'file', array('class' => 'control-label col-xs-2'));?>
                <div class="col-xs-10">
                    <div class="col-xs-12" style="border: 1px solid #CCCCCC;">
                        <div id="mulitplefileuploader">Chọn file</div>
                    </div>
                    <span class="errorMessage"><?php echo isset($valid['file']) ? $valid['file'] : '';?></span>
                    <div id="files">
                        
                    </div>
                </div>
            </div>
            
            <div class="form-group">
                <div class="col-xs-offset-2 col-xs-10">
                    <?php echo Fuel\Core\Form::button('submit', 'Đăng đề thi', array('class' => 'btn background'));?>
                </div>
            </div>
            
            <?php echo Fuel\Core\Form::close();?>
        </div>
    </div>
    <div class="col-xs-3 beta">
        <ul class="nav nav-divider space-section box">
            <li class='<?php echo isset($subnav) && $subnav == "home" ? "active" : ""; ?>'>
                <?php echo \Fuel\Core\Html::anchor('home/index', 'Trang chủ');?>
            </li>
            <li class='<?php echo isset($subnav) && $subnav == "index" ? "active" : ""; ?>'>
                <?php echo \Fuel\Core\Html::anchor('frontend/post/index', 'Đề thi');?>
            </li>
            <li class='<?php echo isset($subnav) && $subnav == "create_post" ? "active" : ""; ?>'>
                <?php echo \Fuel\Core\Html::anchor('frontend/post/create', 'Đăng đề thi');?>
            </li>
            <li class='<?php echo isset($subnav) && $subnav == "index_happy" ? "active" : ""; ?>'>
                <?php echo \Fuel\Core\Html::anchor('frontend/happy/index', 'Chém gió');?>
            </li>
        </ul>
    </div>
</div>
